<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--<p th:text="${user.name}"></p>-->
<table id="from-login">
    <tr>
        <td>email</td>
        <td><input id="username" value="xiefeihong"/></td>
    </tr>
    <tr>
        <td>password</td>
        <td><input id="password" type="password" value="xiefeihong"/></td>
    </tr>
    <tr>
        <td><input type="button" id="btn-login" value="登陆"/></td>
    </tr>
    <p th:if="${param.error}">出错了</p>
</table>
</body>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script>
    $('#btn-login').click(function(){
        $.ajax({
            url:"/user/login",
            type:"POST",
            dataType:"json",
            async:false,
            contentType:"application/json;charset=utf-8",
            data: JSON.stringify(
                {
                    "username":$('#username').val(),
                    "password":$('#password').val()
                }
            ),
            success:function(message){
                if("success"==message.status) {
                    alert(JSON.stringify(message.entity));
                } else {
                    alert(JSON.stringify(message.entity));
                }
            },
            error:function(message){
                alert("fail to post");
            }
        });
    });
</script>
</html>